package com.tomdd.log.controller;

import com.tomdd.log.service.TestService;
import com.tomdd.log.utils.TestThreadLocalUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试控制类
 *
 * @author zx
 * @date 2024年11月26日 14:25
 */
@RequestMapping("/test")
@RestController
@Api(tags = "测试控制类")
@Slf4j
public class TestController {

    @Setter(onMethod_ = @__(@Autowired))
    private TestService testService;

    @GetMapping("/getTestInfo")
    @ApiOperation("获取测试信息")
    @ApiImplicitParam(name = "testMessage", value = "测试消息")
    public String getTestInfo(@RequestParam String testMessage) throws InterruptedException {
        log.info("入参:{},放入请求线程中", testMessage);
        TestThreadLocalUtils.set(testMessage);
        testTrace();
        log.info("开始进行异步插入日志");
        testService.insertLog();
        return "get test info message ...." + testMessage;
    }

    private void testTrace() {
        log.info("这是一行info日志");
        log.error("这是一行error日志");
        testTrace2();
    }

    private void testTrace2() {
        log.info("这也是一行info日志");

    }


}
